4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
16 namespace Microsoft
.JScript
{
19 using System
.Reflection
;
20 using System
.Reflection
.Emit
;
21 using System
.Globalization
;
22 using System
.Diagnostics
;
24 public sealed class JSMethodInfo
: MethodInfo
{
25 internal MethodInfo method
;
26 private MethodAttributes methAttributes
;
27 private String name
= null;
28 private Type declaringType
= null;
29 private ParameterInfo
[] parameters
= null;
30 private Object
[] attributes
= null;
31 private MethodInvoker methodInvoker
= null;
33 internal JSMethodInfo(MethodInfo method
){
35 this.methAttributes
= method
.Attributes
;
38 public override MethodAttributes Attributes
{
40 return this.methAttributes
;
44 public override Type DeclaringType
{
46 Type result
= this.declaringType
;
47 if (result
== null) this.declaringType
= result
= this.method
.DeclaringType
;
52 public override MethodInfo
GetBaseDefinition(){
53 return this.method
.GetBaseDefinition();
56 public sealed override Object
[] GetCustomAttributes(bool inherit
){
57 Object
[] attrs
= this.attributes
;
58 if (attrs
!= null) return attrs
;
59 return this.attributes
= this.method
.GetCustomAttributes(true);
62 public sealed override Object
[] GetCustomAttributes(Type type
, bool inherit
){
63 if (type
!= typeof(JSFunctionAttribute
))
65 Object
[] attrs
= this.attributes
;
66 if (attrs
!= null) return attrs
;
67 return this.attributes
= CustomAttribute
.GetCustomAttributes(this.method
, type
, true);
70 public override MethodImplAttributes
GetMethodImplementationFlags(){
71 return this.method
.GetMethodImplementationFlags();
74 public override ParameterInfo
[] GetParameters(){
75 ParameterInfo
[] parameters
= this.parameters
;
76 if (parameters
!= null) return parameters
;
77 parameters
= this.method
.GetParameters();
78 for (int i
= 0, n
= parameters
.Length
; i
< n
; i
++)
79 parameters
[i
] = new JSParameterInfo(parameters
[i
]);
80 return this.parameters
= parameters
;
84 [DebuggerStepThroughAttribute
]
85 [DebuggerHiddenAttribute
]
87 public override Object
Invoke(Object obj
, BindingFlags options
, Binder binder
, Object
[] parameters
, CultureInfo culture
){
88 MethodInfo method
= TypeReferences
.ToExecutionContext(this.method
);
91 return method
.Invoke(obj
, options
, binder
, parameters
, culture
);
92 }catch(TargetInvocationException e
){
93 throw e
.InnerException
;
96 MethodInvoker invoker
= this.methodInvoker
;
98 this.methodInvoker
= invoker
= MethodInvoker
.GetInvokerFor(method
);
99 if (invoker
== null) //because the method is not safe to call via a thunk
101 return method
.Invoke(obj
, options
, binder
, parameters
, culture
);
102 }catch(TargetInvocationException e
){
103 throw e
.InnerException
;
106 return invoker
.Invoke(obj
, parameters
);
109 public sealed override bool IsDefined(Type type
, bool inherit
){
110 Debug
.PreCondition(type
== typeof(JSFunctionAttribute
));
111 Object
[] attrs
= this.attributes
;
113 this.attributes
= attrs
= CustomAttribute
.GetCustomAttributes(this.method
, type
, true);
114 return attrs
.Length
> 0;
117 public override MemberTypes MemberType
{
119 return MemberTypes
.Method
;
123 public override RuntimeMethodHandle MethodHandle
{
125 return this.method
.MethodHandle
;
129 public override String Name
{
131 String result
= this.name
;
132 if (result
== null) this.name
= result
= this.method
.Name
;
137 public override Type ReflectedType
{
139 return this.method
.ReflectedType
;
143 public override Type ReturnType
{
145 return this.method
.ReturnType
;
149 public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
151 return this.method
.ReturnTypeCustomAttributes
;
155 public override String
ToString(){
156 return this.method
.ToString();